<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .content {
        width: 300px;
        height: 300px;
        border: 1px solid black;
      }
      .drag-box {
        width: 100px;
        height: 100px;
        background-color: blue;
        cursor: move;
      }
    </style>
  </head>
  <body>
    <div class="content"></div>
    <div class="drag-box" draggable></div>

    <script>
      const content = document.querySelector(".content");
      const dragBox = document.querySelector(".drag-box");

      content.addEventListener("dragover", (e) => {
        console.log("dragover");
        e.preventDefault();
      });

      content.addEventListener("drop", (e) => {
        console.log("drop");
        e.preventDefault();
        const data = e.dataTransfer.getData("text/plain");
        e.target.innerText = data;
        // content.appendChild(dragBox);
      });

      content.addEventListener("dragenter", (e) => {
        console.log("dragenter");
      });

      content.addEventListener("dragleave", (e) => {
        console.log("dragleave");
      });

      dragBox.addEventListener("dragstart", (e) => {
        console.log("dragstart");
        e.dataTransfer.setData("text/plain", "dragBox");
        e.dataTransfer.setDragImage(dragBox, 50, 50);
      });

      dragBox.addEventListener("dragend", (e) => {
        console.log("dragend");
      });
    </script>
  </body>
</html>
